package com.theme.passport.controller.theme;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.theme.WidgeTypeEntity;
import com.theme.passport.service.theme.WidgeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * 组件类型表
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2022-06-21 10:01:48
 */
@RestController
@RequestMapping("widge/widge-type")
public class WidgeTypeController {
    @Autowired
    private WidgeTypeService widgeTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("widge:widge-type:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = widgeTypeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("widge:widge-type:info")
    public R info(@PathVariable("id") Long id){
		WidgeTypeEntity widgeTypeEntity = widgeTypeService.getById(id);

        return R.ok().put("widgeType", widgeTypeEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("widge:widge-type:save")
    public R save(@RequestBody WidgeTypeEntity widgeTypeEntity){
        widgeTypeEntity.setCreated(new Date());
        widgeTypeService.save(widgeTypeEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("widge:widge-type:update")
    public R update(@RequestBody WidgeTypeEntity widgeTypeEntity){
        widgeTypeEntity.setUpdated(new Date());
        widgeTypeService.updateById(widgeTypeEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("widge:widge-type:delete")
    public R delete(@RequestBody Long[] ids){
        widgeTypeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
